package com.qi.qipay.commons.controller;

import com.qi.qipay.commons.utils.WebUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

public abstract class BaseController {


    protected abstract Object doing(String servicePrefix, String methodName, Map<String, Object> paramMap) throws Exception;

    protected abstract String getServiceName(String servicePrefix);

    public Object doRequest(HttpServletRequest request, HttpServletResponse response,
                            String servicePrefix, String methodName) {
        Map<String, Object> paramMap = null;
        Object result;
        try {
            paramMap= WebUtil.getParamMap(request);
            result = doing(servicePrefix, methodName, paramMap);
        } catch (Exception e) {
            result = e;
        }
        //强制要求客户端关闭此http连接
        response.setHeader("Connection", "close");
        //设置返回内容
        response.setContentType("application/json;charset=UTF-8");
        return result;
    }
}
